<template>
  <div class="my">
    <!-- 封图 -->
    <div class="photo">
      <img src="../assets/Sealingmap.png" alt="" />
    </div>

    <!-- 用户信息 -->
    <div class="user">
      <!-- 用户名 -->
      <div class="news">
        <div class="name">
          {{ username }}
          <div class="vip">VIP1</div>
        </div>
        <div class="txt">消费满1元可升至VIP2</div>
      </div>

      <!-- 头像 -->
      <van-image
        round
        width="80px"
        height="80px"
        :src="imgData"
        @click="goMydata"
      />
    </div>

    <!-- 成长好礼 -->
    <div class="growup">
      <div class="title">
        成长好礼
        <div class="txt add" @click="goExchange">
          累积灵感值，领限量礼券
          <van-icon name="arrow" />
        </div>
      </div>

      <div class="txt">本月已积累0灵感值</div>

      <van-steps :active="active">
        <van-step></van-step>
        <van-step><img src="../assets/my/box.svg" alt="" /></van-step>
        <van-step></van-step>
        <van-step><img src="../assets/my/box.svg" alt="" /></van-step>
      </van-steps>
    </div>

    <!-- 会员服务 -->
    <div class="service">
      <div class="title">会员服务</div>

      <van-grid :column-num="4">
        <van-grid-item icon="qr-invalid" text="会员码" @click="goCode" />
        <van-grid-item icon="records" text="我的订单" @click="goMyorder" />
        <van-grid-item icon="like-o" text="我的收藏" @click="goCollection" />
        <van-grid-item icon="logistics" text="地址管理" @click="goReceiving" />
        <van-grid-item icon="service-o" text="我的客服" @click="goCustomer" />
        <van-grid-item icon="bullhorn-o" text="消息中心" @click="goNews" />
        <van-grid-item icon="gift-o" text="兑换中心" @click="goExchange" />
        <van-grid-item icon="discount" text="设置" @click="goSetup" />
      </van-grid>
    </div>
  </div>
</template>

<script>
export default {
  name: "My",

  data() {
    return {
      active: 0,

      imgData: "",
      username: "",
    };
  },

  created() {
    this.getHeadPortrait();
  },

  methods: {
    //跳转编辑个人资料
    goMydata() {
      this.$router.push({ name: "Mydata" });
    },

    //跳转到会员码页面
    goCode() {
      this.$router.push({ name: "Code" });
    },

    //跳转到订单页面
    goMyorder() {
      this.$router.push({ name: "Myorder" });
    },

    //跳转到收藏页面
    goCollection() {
      this.$router.push({ name: "Collection" });
    },

    //跳转到消息中心页面
    goNews() {
      this.$router.push({ name: "News" });
    },

    //跳转到地址页面
    goReceiving() {
      this.$router.push({ name: "Receiving" });
    },

    //跳转到我的客服页面
    goCustomer() {
      this.$router.push({ name: "Customer" });
    },

    //跳转到兑换中心页面
    goExchange() {
      this.$router.push({ name: "Exchange" });
    },

    //跳转到设置页面
    goSetup() {
      this.$router.push({ name: "Setup" });
    },

    //获取我的头像
    getHeadPortrait() {
      this.axios({
        method: "get",
        url: "/findMy",
      })
        .then((res) => {
          // 

          // 未登录跳转到登录页面
          if (res.data.code === 700) {
            this.$router.push({ name: "Login" });
          }

          // 查询成功
          if (res.data.code === "A001") {
            this.username = res.data.result[0].nickName;
            this.imgData = res.data.result[0].userImg;
          }
        })
        .catch((err) => {
          
        });
    },
  },
};
</script>

<style lang="less" scoped>
.my {
  overflow-y: auto;
  margin-bottom: 30px;
}

// 封图
.photo {
  width: 100%;
  height: 274px;
}

.photo img {
  width: 100%;
  height: 274px;
}

// 用户信息
.user {
  width: 300px;
  height: 60px;
  margin: auto;
  border-radius: 10px;
  padding: 10px 16px;
  background-color: #fff;
  position: relative;
  bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.news {
  width: 200px;
  height: 40px;
  display: flex;
  flex-wrap: wrap;
}

.name {
  width: 100%;
  height: 24px;
  line-height: 24px;
  font-weight: 600;
  font-size: 16px;
  display: flex;
}

.vip {
  width: 60px;
  transform: scale(0.5);
  text-align: center;
  border-radius: 10px;
  background-color: #adcff6;
  font-weight: 600;
}

.txt {
  width: 100%;
  height: 20px;
  line-height: 20px;
  font-size: 12px;
  color: #999;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  &.add {
    width: 200px;
    text-align: right;
    margin-left: auto;
  }
}

/deep/.van-image {
  position: relative;
  bottom: 20px;
}

//成长好礼、会员服务
.service,
.growup {
  width: 300px;
  margin: 10px auto;
  border-radius: 10px;
  padding: 10px 16px;
  background-color: #fff;
  position: relative;
  bottom: 20px;
}

.title {
  width: 100%;
  height: 20px;
  line-height: 20px;
  font-size: 16px;
  padding: 0 0 6px 0;
  display: flex;
}

/deep/.van-step--horizontal .van-step__title img {
  width: 16px;
  height: 16px;
}
</style>